package org.dromara.order.controller;

import lombok.extern.slf4j.Slf4j;
import org.dromara.order.OrderProperties;
import org.dromara.order.bean.Order;
import org.dromara.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
//@RefreshScope
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    //    @Value("${order.timeout}")
//    String orderTimeout;
//    @Value("${order.auto-confirm}")
//    String orderAutoConfirm;
    @Autowired
    OrderProperties orderProperties;

    @GetMapping("/create")
    public Order createOrder(@RequestParam Long productId, @RequestParam Long userId) {
        Order order = orderService.createOrder(productId, userId);
        log.info("创建订单成功：{}", order);
        return order;
    }


    @GetMapping("/config")
    public String config() {
        return "orderTimeout:" + orderProperties.getTimeout() + ",orderAutoConfirm:" + orderProperties.getAutoConfirm()+",dbUrl:"+orderProperties.getDbUrl();
    }
}
